from tencentcloud.common import credential
from tencentcloud.sms.v20210111 import sms_client, models


def send_sms(mobile,sms_code):
    mobile = "+86{}".format(mobile)

    try:
        cred = credential.Credential("AKID33tZBew30n5DBzd8TfgYGoCPTMD1f9Uf", "75uZ4PbeXGpETbZOqJdmlaEj5IMI5iBa")
        client = sms_client.SmsClient(cred, "ap-guangzhou")

        req = models.SendSmsRequest()

        req.SmsSdkAppId = "1400935775"
        req.SignName = "合肥起风网络科技有限公司"
        req.TemplateId = "2304391"
        req.TemplateParamSet = [sms_code]  #这个是干嘛的
        req.PhoneNumberSet = [mobile,]
        resp = client.SendSms(req)
        # data_dict = resp.SendStatusSet[0]
        # print(data_dict, type(data_dict))
        data_object = resp.SendStatusSet[0]
        print(data_object,type(data_object))
        print(data_object.Code)
        # if data_dict.get('Code') == 'OK':
        if data_object.Code == 'Ok':
            return True
    except Exception as e:
        print(e)